package com.hoongs.v1.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.hoongs.v1.utils.DateUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Repository
@TableName(value = "product")
@JsonIgnoreProperties(value = {"createTime", "updateTime"})
public class Product {

    @TableId(type = IdType.ASSIGN_UUID)
    private String id;

    private String image;

    @TableField(value = "image_thumb")
    private String imageThumb;

    @NotBlank(message = "请输入商品名称")
    private String name;

    private String status = "1";         // 商品状态 0:下架 1:正常 2:售完

    @NotNull(message = "请录入商品价格")
    private BigDecimal price;         // 商品价格

    @NotNull(message = "请输入商品原价")
    @TableField(value = "original_price")
    private BigDecimal originalPrice;         // 商品原价（未优惠价格）

    private BigDecimal stock;         // 商品库存

    private String size = "";         // 商品规格
    @TableField(value = "size_dict_value")
    private String sizeDictValue = "";

    @NotBlank(message = "请选择商品类型")
    private String type = "1";          //  商品类型 1:普通商品 2:套餐 3:小料

    @NotBlank(message = "请选择商品分类")
    @TableField(value = "cate_id")
    private String cateId;      // 商品分类id

    @NotBlank(message = "请输入商品分类名称")
    @TableField(value = "cate_name")
    private String cateName;      // 商品分类名称

    private String summary;         // 商品简介

    private String remark;         // 商品备注

    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;       // 发布时间

    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;    // 更新时间

}
